﻿using MediatR;
using W.Purchase.API.Application.Command.ReceivableCommand;
using W.Purchase.Repository.Impl;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ReceivableCommandHandler
{
    public class ReceivableDelCommandHandler:IRequestHandler<ReceivableDelCommand,int>
    {
        private readonly IReceivableRepository _ireceivableRepository;
        public ReceivableDelCommandHandler(IReceivableRepository ireceivableRepository)
        {
            _ireceivableRepository = ireceivableRepository;
        }

        public async Task<int> Handle(ReceivableDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _ireceivableRepository.GetAllAsaync();
            var plist = list.Where(c => c.ReceivableId == request.ReceivableId).FirstOrDefault();
            if (plist != null)
            {
                plist.IsDelete = true;
            }
            return await _ireceivableRepository.Update(plist);
        }
    }
}
